{% extends "base.html" %}
{% load compress static hc_extras %}

{% block content %}

<div class="row">
<form
    id="add-credential-form"
    class="col-sm-6 col-sm-offset-3"
    method="post"
    encrypt="multipart/form-data">
    <h1>Add Security Key</h1>

    {% csrf_token %}
    <input id="response" type="hidden" name="response">

    <div class="form-group">
        <label for="name">Name</label>
        <input
            type="text"
            class="form-control"
            id="name"
            name="name"
            required>
        <div class="help-block">
            Give this credential a descriptive name. Example: "My primary Yubikey"
        </div>
    </div>

    <div class="form-group text-right">
        <button
            id="name-next"
            class="btn btn-default" type="button">
            Confirm Name and Continue
        </button>
    </div>

    <div id="waiting" class="hide">
        <h2>Waiting for security key</h2>
        <p>
            Follow your browser's instructions to register your security key
            with {% site_name %}.
        </p>

        <div class="spinner started"></div>
    </div>

    <div id="error" class="alert alert-danger hide">
        <p>
            <strong>Something went wrong.</strong>
        </p>
        <p id="error-text"></p>

        <div class="text-right">
            <button id="retry" type="button" class="btn btn-danger">
                Try Again
            </button>
        </div>
    </div>

    <div id="success" class="hide">
        <div class="alert alert-success">
            <strong>Success!</strong>
            Credential acquired.
        </div>

        <div class="form-group text-right">
            <input
                id="add-credential-submit"
                class="btn btn-primary"
                type="submit"
                name=""
                value="Save Security Key">
        </div>
    </div>
</form>
</div>

{{ options|json_script:"options" }}

{% endblock %}

{% block scripts %}
{% compress js %}
<script src="{% static 'js/webauthn-json.browser-global.js' %}"></script>
<script src="{% static 'js/add_credential.js' %}"></script>
{% endcompress %}
{% endblock %}
